package com.linln.modules.insurance.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.linln.common.utils.DateUtil;
import com.linln.common.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linln.modules.insurance.repository.InsuranceOfferMapper;
import com.linln.modules.insurance.domain.InsuranceOffer;
import com.linln.modules.insurance.service.InsuranceOfferService;

import java.util.Date;

/**
 * @author : pengliang
 * @version V1.0
 * @Project: timo
 * @Package com.linln.modules.userule.service.impl
 * @Descriptio /**
 * @Project: timo
 * @Package com.linln.modules.userule.service.impl
 * @Description: TODO
 * @date Date : 2020年12月29日 14:23
 */

@Service
public class InsuranceOfferServiceImpl extends ServiceImpl<InsuranceOfferMapper, InsuranceOffer> implements InsuranceOfferService {

    @Autowired
    private InsuranceOfferMapper insuranceOfferMapper;

    @Override
    public boolean addInsuranceOffer(InsuranceOffer insuranceOffer) {
        insuranceOffer.setCreateDate(DateUtil.formatDate(new Date()));
        return this.save(insuranceOffer);
    }


    @Override
    public PageResult<InsuranceOffer> getInsuranceOffer(Integer pageNum, Integer limit, String ownerName, String ownerPhone, Boolean status) {
        PageHelper.startPage(pageNum, limit);
        PageInfo<InsuranceOffer> pageInfo = new PageInfo<>(insuranceOfferMapper.selectInsuranceOffer(ownerName, ownerPhone, status));
        PageResult<InsuranceOffer> pageResult = new PageResult<>();
        pageResult.setCount(pageInfo.getTotal());
        pageResult.setData(pageInfo.getList());
        return pageResult;
    }

    @Override
    public boolean updateInsuranceOfferStatus(String ioId, long userId) {
        InsuranceOffer insuranceOffer = new InsuranceOffer();
        insuranceOffer.setOfferDate(DateUtil.formatDate(new Date()));
        insuranceOffer.setOfferPeopleId(String.valueOf(userId));
        insuranceOffer.setStatus(true);
        insuranceOffer.setIoId(ioId);
        return this.updateById(insuranceOffer);
    }
}
